package com.xy.controller;

import com.xy.dao.RolePermsDao;
import com.xy.dao.UserRoleDao;
import com.xy.model.*;
import com.xy.service.*;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * 这是测试的控制器，不用管
 *
 */
@RestController
public class TestController {
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;
    @Autowired
    PermissionService permissionService;
    @Autowired
    UserRoleService userRoleService;
    @Autowired
    RolePermissionService rolePermissionService;

    @PostMapping("/user/add")
    public Integer addUser(User user){

        return userService.addUser(user);
    }
    @GetMapping("/user/del/{id}")
    public Integer delUser(@PathVariable("id") Integer id){
        return userService.delUser(id);
    }
    @PostMapping("/user/find")
    public User getUser(String username){
        return userService.getUserByName(username);
    }

    @GetMapping("/role/find/{id}")
    public Set<String> getRoles(@PathVariable("id") Integer id){
        return roleService.getRoles(id);
    }
    @GetMapping("/role/findall/")
    public Set<String> getRolesAll(){
        return roleService.getRolesAll();
    }
    @GetMapping("/role/findbyid/{id}")
    public List<Role> getRolesById(@PathVariable("id") Integer id){
        return roleService.getRolesForRole(id);
    }
    @PostMapping("/role/add/")
    public Integer addRole(Role role){
        return roleService.addRole(role);
    }
    @GetMapping("/role/del/{id}")
    public Integer delRole(@PathVariable("id") Integer id){
        return roleService.delRole(id);
    }
    @GetMapping("/pers/find/{id}")
    public Set<String> getPers(@PathVariable("id") Integer id){
        return permissionService.getPermission(id);
    }
    @GetMapping("/pers/findbyid/{id}")
    public List<Permission> getPersById(@PathVariable("id") Integer id){
        return permissionService.getPermissionByList(id);
    }
    @GetMapping("/pers/findall")
    public List<Permission> getPermissionAll(){
        return permissionService.getPermissionAll();
    }
    @PostMapping("/ur/add")
    public Integer addUserRole(UserAndRole userAndRole){
        return userRoleService.addUserRole(userAndRole);
    }
    @PostMapping("/ur/del")
    public Integer delUserRole(Integer userId,Integer roleId){
        return userRoleService.delUserRole(userId,roleId);
    }
    @PostMapping("/rp/add")
    public Integer addRoleP(RoleAndPerms roleAndPerms) {
        return rolePermissionService.addRolePerms(roleAndPerms);
    }
    @PostMapping("/rp/del")
    public Integer delRolePer(Integer roleId ,Integer permsId){
        return rolePermissionService.delRolePerms(roleId,permsId);
    }
}
